/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler;

import bbd.crawler.job.ArtistNamesJob;
import bbd.crawler.job.ThreadedJobManager;
import bbd.crawler.media.Scheduler;
import bbd.crawler.util.Console;

import java.util.ArrayList;

/**
 *
 * @author Amogh
 */
public class Crawler {

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public Crawler() { } // end of default constructor

    //--------------------------------------------------------------------------
    //                          PUBLIC METHODS
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    /** 
     * Begin crawling the locations for the data we need. Crawling happens in a
     * specific order. The order is as follows -
     *
     *      1. Get the artist names delta
     *
     *              This is the list of artists to be crawled from the internet
     *              that are not already in the data base.
     *
     *      2. Get the information about the artists
     *
     *              Get the information from various locations listed.
     *
     *      3. Segregate the artists into bands and artists
     *
     *      4. Get the albums for the artists and bands just crawled
     *
     *      5. Get the songs for the albums just crawled
     *
     *      6. Finally get the media links for the songs just crawled
     */
    public void beginCrawl () 
            throws Exception
    {
        ArtistNamesJob namesJob = new ArtistNamesJob();

        Console.message ( "Getting list of artist names to crawl." );
        
        namesJob.execute();

        ArrayList aNames = (ArrayList) namesJob.getJobOutput();

        Console.message ( "Found " + aNames.size() + " artist(s) ... " );

        ThreadedJobManager jobManager = new ThreadedJobManager (aNames);
        
        Console.message ( "Getting artist information." );

        /* change it later to get all artists names*/
        jobManager.startJobs();

        /* testing for media URLS */
        Scheduler instance = Scheduler.getInstance();

        if ( instance != null ) {

            //instance.crawl("Dire Straits");
            
        }

        
        
    } // end function beginCrawl

} // end class Crawler
